powerpc/bpf: fix alignment of long branch trampoline address - #8655
Open
kernel-patches-daemon-bpf-rc[bot] wants to merge 8 commits into
Open
powerpc/bpf: fix alignment of long branch trampoline address#8655kernel-patches-daemon-bpf-rc[bot] wants to merge 8 commits into
kernel-patches-daemon-bpf-rc[bot] wants to merge 8 commits into
Conversation
Author
|
Upstream branch: 41c129f |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 7, 2026 13:04
bbe1ae8 to
dd2acb0
Compare
Author
|
Upstream branch: 2b1f9f6 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142165=>bpf-next
branch
from
August 7, 2026 13:06
8bbf3f7 to
957ea70
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 7, 2026 21:09
dd2acb0 to
75f1c0e
Compare
Author
|
Upstream branch: e1d9b82 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142165=>bpf-next
branch
from
August 7, 2026 21:14
957ea70 to
271fccf
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 7, 2026 22:48
75f1c0e to
f776207
Compare
Author
|
Upstream branch: 51476f6 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142165=>bpf-next
branch
from
August 7, 2026 22:50
271fccf to
fe8c7d0
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 8, 2026 10:01
f776207 to
b882df0
Compare
Author
|
Upstream branch: 8b365b3 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142165=>bpf-next
branch
from
August 8, 2026 10:03
fe8c7d0 to
50593af
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 8, 2026 10:13
b882df0 to
818432c
Compare
added 7 commits
August 8, 2026 03:15
Ensure the dummy trampoline address field present between the OOL stub and the long branch stub is 8-byte aligned, for memory compatibility when content loaded to a register. Reported-by: Hari Bathini <hbathini@linux.ibm.com> Fixes: d243b62 ("powerpc64/bpf: Add support for bpf trampolines") Cc: stable@vger.kernel.org Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com>
Move the long branch address field to the bottom of the long branch stub. This allows uninterrupted disassembly until the last 4/8 bytes. The last bytes exclusion is logically necessary to prevent disassembly failure, otherwise the actual program layout is never altered. Hence no effect on overall program size. Also, align dummy_tramp_addr field with 8-byte boundary. Following is disassembler output for test program with moved down dummy_tramp_addr field: ..... ..... pc:68 left:44 a6 03 08 7c : mtlr 0 pc:72 left:40 bc ff ff 4b : b .-68 pc:76 left:36 a6 02 68 7d : mflr 11 pc:80 left:32 05 00 9f 42 : bcl 20, 31, .+4 pc:84 left:28 a6 02 88 7d : mflr 12 pc:88 left:24 14 00 8c e9 : ld 12, 20(12) pc:92 left:20 a6 03 89 7d : mtctr 12 pc:96 left:16 a6 03 68 7d : mtlr 11 pc:100 left:12 20 04 80 4e : bctr pc:104 left:8 c0 34 1d 00 : Failure log: Can't disasm instruction at offset 104: c0 34 1d 00 00 00 00 c0 Disassembly logic can truncate at 104, ignoring last 8 bytes. Update the dummy_tramp_addr field offset calculation from the end of the program to reflect its new location, for bpf_arch_text_poke() to update the actual trampoline's address in this field. All BPF trampoline selftests continue to pass with this patch applied. Fixes: d243b62 ("powerpc64/bpf: Add support for bpf trampolines") Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com>
Ensure that the trampoline stubs JITed at the tail of the epilogue do not expose the dummy trampoline address stored in the last 8 bytes(64-bit) and last 4 bytes(32-bit) to the disassembly flow. Prevent the disassembler from ingesting this memory address, as it may occasionally decode into a seemingly valid but incorrect instruction. Fix this issue by truncating the last 8/4 bytes from JITed buffers before supplying them for disassembly. Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com> Reviewed-by: Hari Bathini <hbathini@linux.ibm.com>
Enable "__arch_powerpc64" specifier in verifier selftest for ppc64. Power 32-bit would require separate handling. Changes tested for 64-bit only. Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Reviewed-by: Hari Bathini <hbathini@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com>
The tail_call_info field can contain either a scalar counter value or a 64-bit pointer to the counter, using a 32-bit compare (cmplwi) only checks the lower 32 bits, which can lead to incorrect comparisions when location of counter is near 4GB boundary. Use instruction cmpldi/cmplwi for accurate comparision in corresponding cases. Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/bpf/20260517191450.85AE6C2BCB8@smtp.kernel.org/ Fixes: 2ed2d8f ("powerpc64/bpf: Support tailcalls with subprogs") Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com> Acked-by: Hari Bathini <hbathini@linux.ibm.com>
Verifier testcase result for tailcalls: Summary: 2/3 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com>
During size calculation in pass-0, exit_addr is 0 since addrs[fp->len] is not yet populated. bpf_jit_emit_exit_insn() treats a zero exit_addr as in-range and skips bpf_jit_build_epilogue(), so the alternate inline epilogue instructions are not counted in alloclen. In later passes, if the real exit_addr falls outside the 32MB branch range, the full inline epilogue is emitted into the already-allocated buffer, writing past its end and corrupting adjacent memory. Fix by ensuring exit_addr is non-zero before treating it as in-range, so pass-0 always falls through to bpf_jit_build_epilogue() and conservatively accounts for all epilogue instructions in alloclen. Also range check alt_exit_addr directly in the else-if condition. Since exit_addr handling now falls through to the epilogue, two related issues in bpf_int_jit_compile() must also be addressed: 1. Reset cgctx.alt_exit_addr before the second size-calculation pass. Without this, a stale alt_exit_addr from the first pass causes the second pass to emit a single jump instead of the full epilogue, undercounting alloclen and reintroducing the overflow. 2. Recompute addrs[fp->len] at the end of each code-generation pass. The larger pass-0 body can shrink in later passes as out-of-range exits settle into in-range jumps; a stale addrs[fp->len] would leave exit branches targeting past the real (shrunken) epilogue. Because shrinkage in a later pass can move the epilogue offset, the fixed two-pass loop is no longer sufficient: an exit that was out of range in an earlier pass may fall in range once the epilogue offset shrinks, shrinking the body further and overwriting the start of the epilogue. Convert the code-generation loop to iterate until the program size converges, bounded by CODEGEN_MAX_PASSES, and fail the JIT if it does not converge. Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/bpf/20260529015855.364704-2-adubey@linux.ibm.com/T/#mfcb23909d977b949727cca4f59ee56a13fd69b92 Fixes: d243b62 ("powerpc64/bpf: Add support for bpf trampolines") Cc: stable@vger.kernel.org Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Link: https://lore.kernel.org/bpf/20260529015855.364704-2-adubey@linux.ibm.com/T/#mfcb23909d977b949727cca4f59ee56a13fd69b92 Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com>
Author
|
Upstream branch: d114bb9 |
The existing conditional statement in bpf_int_jit_compile() frees the percpu private stack at out_addrs only when the image buffer was never allocated. If bpf_jit_build_body() fails during a code-generation pass, the image buffer has already been allocated, so !image is false and the percpu stack is not freed. Because JIT compilation failed, fp->jited remains at 0. The subsequent bpf_jit_free() path only frees priv_stack_ptr when fp->jited is set, so freeing is skipped here too, leaking the percpu allocation. Fix implements freeing the private stack whenever fp->jited was not set, i.e. compilation did not succeed, instead of keying off !image. !fp->jited already covers the !image case, since image is only NULL on early-failure paths where fp->jited is likewise 0. Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/bpf/20260616135426.A06B71F000E9@smtp.kernel.org Fixes: 156d985 ("powerpc64/bpf: Implement JIT support for private stack") Cc: stable@vger.kernel.org Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com> Tested-by: Yeswanth Krishna Tellakula <yeswanth@linux.ibm.com> Acked-by: Hari Bathini <hbathini@linux.ibm.com>
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142165=>bpf-next
branch
from
August 8, 2026 10:15
50593af to
f56d24e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: powerpc/bpf: fix alignment of long branch trampoline address
version: 11
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1142165